Add Buttons to a Form

For example, let's see how to add a button to a form.

  1. Open the Toolbox:
  2. Double-click Button to add it to the form
  3. Change the Text property of the button
  4. Change the Name property
  5. Save your project as:

Add functionality to the button

If you want to display a message when the button is clicked, a piece of code must be added to the button. Double-click the button to display the code window. It shows the automatically generated code for the whole form application.

The following code will create a pop up window and display a message:
MessageBox.Show("Thanks for clicking the button!");
The completed code should look like

Click Save All.
Let's test the program by clicking Start to run the program!

Congratulations! Here is how it looks:


Create another button

Repeat the steps to add an exit button to the form. Use the following Button properties:

  1. Text: Exit the form
  2. Name: exitButton
  3. Code for the button: this.Close();
  4. Save All
  5. Run the program to see


For more details, please contact me here.
Date of last modification: March 17, 2019